const router = require('express').Router()
let users = [
  { id: 1, name: '张三' },
  { id: 2, name: '李四' }
];

// api/users
router.get('/users', (req, res) => {
  res.send({
    code: 0,
    msg: 'ok',
    data: users
  })
})

router.post('/users', (req, res) => {
  let name = req.body.name
  let user = { id: Date.now(), name }
  users.push(user)
  res.status(201).send({
    code: 0,
    msg: 'ok',
    data: user,
    // users
  })
})


module.exports = router